package yuan.deng.spb.uservice.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import yuan.deng.spb.domain.User;
import yuan.deng.spb.mapper.UserMapper;
import yuan.deng.spb.uservice.UserService;

import java.util.List;

/**
 * @Description:
 * @Version: V1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public String findPassword(String s) {
        String username=null;

        username = (String) redisTemplate.boundValueOps(s).get();
        if (username==null){
            username=userMapper.findPassword(s);
            redisTemplate.boundValueOps(s).set(username);
            System.out.println("数据库");
        }

        return username;
    }
}
